package com.cx.base.dao.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class QueryStandardUtil {

	public static List<Map<String, Object>> getStandardList(List<Map<String, Object>> list) {
		List<Map<String, Object>> reList = new ArrayList<Map<String, Object>>();
		if(list != null && list.size() > 0){
			Map<String, String> keyMap = getMapKey(list.get(0));
			for(Map<String, Object> m : list){
				Map<String, Object> reMap = new HashMap<String, Object>();
				//遍历
				for (Map.Entry<String, Object> entry : m.entrySet()) {
				  reMap.put(keyMap.get(entry.getKey()), entry.getValue());
				}
				reList.add(reMap);
			}
		}
		return reList;
	}

	public static Map<String, Object> getStandardMap(Map<String, Object> map) {
		if(map != null){
			Map<String, Object> reMap = new HashMap<String, Object>();

			//遍历
			for (Map.Entry<String, Object> entry : map.entrySet()) {  
			  String key = entry.getKey();
			  key = getKey(key);
			  reMap.put(key, entry.getValue());
			}
			return reMap;
		}
		return null;
	}
	
	
	public static Map<String, String> getMapKey(Map<String, Object> map) {
		Map<String, String> reMap = new HashMap<String, String>();
		if (map != null) {
			// 遍历
			for (Map.Entry<String, Object> entry : map.entrySet()) {
				String key = entry.getKey();
				String value = getKey(key);
				reMap.put(key, value);
			}
		}
		return reMap;
	}
	
	public static String getKey(String str){
		while (str.indexOf("_") > -1) {
			Integer i = str.indexOf("_");
			//字母大写
			String big = str.substring(i+1, i+2).toUpperCase();
			str = str.substring(0,i)+big+str.substring(i+2,str.length());
		}
		
		return str;
	}
}
